<?php
include dirname(__FILE__).'/taobaoAPI.php';
class taobaoCom extends  taobaoApi{
	const allCatsFile =  'allCats.php';
	const provincesFile = 'provinces.php';
	
	public function __construct() {
		
	//TODO - Insert your code here
	}

	function getSonCats($parentCid)
	{
		include(self::allCatsFile);
		$allCats = unserialize($allCatsStr);
		foreach($allCats as $cat)
		{
			if ($cat['parent_cid']==$parentCid)
			{
				$cats[]=$cat;
			}
		}
		return $cats;
	}
	function showProvinces()
	{
		include(self::provincesFile);
		return $provinces = unserialize($provincesStr);
	}
	function numofpage($page,$numofpage,$max=null)
	{
		$total = $numofpage;
		if (!empty($max)) {
			$max = (int)$max;
			$numofpage > $max && $numofpage = $max;
		}
		if ($numofpage <= 1 || !is_numeric($page)) {
			return '';
		} else{
			$pages ='<script language="javascript" type="text/javascript">function goPage(p){document.condition.p.value=p;document.condition.submit();}</script>';
			$pages .= "<div class=\"pages\"><a href=\"JavaScript:goPage(1);\" style=\"font-weight:bold\">&laquo;</a>";
			for ($i=$page-3;$i<=$page-1;$i++) {
				if($i<1) continue;
				$pages .= "<a href=\"JavaScript:goPage($i);\"> $i </a>";
			}
			$pages .= "<b> $page </b>";
			if ($page < $numofpage) {
				$flag = 0;
				for ($i=$page+1;$i<=$numofpage;$i++) {
					$pages .= "<a href=\"JavaScript:goPage($i);\"> $i </a>";
					$flag++;
					if ($flag==4) break;
				}
			}
			$pages .= "<input type=\"text\" size=\"3\" onkeydown=\"javascript: if(event.keyCode==13){ goPage(this.value);return false;}\"><a href=\"JavaScript:goPage($numofpage);\" style=\"font-weight:bold\">&raquo;</a> Pages: ( $page/$total total )</div>";
			return $pages;
		}
	}	
}


?>